def nado(a):
    b = True 
    if len(str(a)) != 3:
        b = False
    for i in range(2, int(a ** 0.5) + 1):
        if a % i == 0:
            b = False
            break
    return b

oprst = {
    "zero": 0,
    "one": 1,
    "two": 2,
    "three": 3,
    "four": 4,
    "five": 5,
    "six": 6,
    "seven": 7,
    "eight": 8,
    "nine": 9}
a = input().split()
if len(a) != 3 or not (set(a) <= set(oprst.keys())):
    print("Wrong input")
    exit()

a = oprst[a[0]] * 100 + oprst[a[1]] * 10 + oprst[a[2]]

br = a + 1
while not nado(br):
    br += 1
gh = a - 1
while not nado(gh):
    gh -= 1
if abs(a - br) >= abs(a - gh):
    print(gh)
else:
    print(br)